from selenium import webdriver
from selenium.webdriver.common.by import By


class BasePage(object):
    def __init__(self, driver):
        self.driver = driver

    def get_element(self, *loc):
        return self.driver.find_element(*loc)

    # 多参，要解的放后面
    def input_text(self, value, *loc):
        self.get_element(*loc).send_keys(value)

    def get_click(self, *loc):
        self.driver.find_element(*loc).click()

    def get_title(self,):
        return self.driver.title


class BaiDuPage(BasePage):
    def __init__(self, driver):
        BasePage.__init__(self, driver)
        driver.get('http://www.baidu.com')

    def search(self):
        # 在输入框输入要查询的内容
        loc = (By.ID, 'kw')
        self.input_text('selenium', *loc)
        # 点击搜索按钮
        loc2 = (By.ID, 'su')
        self.get_click(*loc2)


if __name__ == '__main__':
    d = webdriver.Chrome()
    baidupage = BaiDuPage(d)
    baidupage.search()


